@extends('admin.layout.base')
@section('title', '帮助中心列表页面')
@section('pluginstyle')
<meta name="csrf-token" content="{{ csrf_token() }}" />
@endsection
@section('content')
<div class="content-wrapper">
    <!-- Content Header (Page header) -->
    <section class="content-header">
        <h1>
            帮助中心列表页面
        </h1>
        <ol class="breadcrumb">
            <li><a href="{{ url('/admin') }}"><i class="fa fa-dashboard"></i> 首页</a></li>
            <li class="active">帮助中心管理</li>
        </ol>
    </section>
    <!-- Main content -->
    <section class="content">
        <div class="row">
            <div class="col-xs-12">
                <div class="box">
                    <div class="box-header">
                        <a class="btn btn-success" href="{{ url('/admin/faq/fc/create') }}">
                            <i class="fa fa-plus"></i> 添加分类
                        </a>
                        <div class="box-tools">
                            <form action="{{ url('/admin/faq/fc') }}" method="get">
                            <div class="input-group" style="width: 150px;">
                                <input type="text" name="cate_name" value="{{ old('cate_name') }}" class="form-control pull-right" placeholder="分类名称">
                                <div class="input-group-btn">
                                    <button type="submit" class="btn btn-default"><i class="fa fa-search"></i></button>
                                </div>
                            </div>
                            </form>
                        </div>
                    </div>
                    <!-- /.box-header -->
                    <div class="box-body table-responsive no-padding">
                        <table class="table table-hover table-bordered">
                            <tr>
                                <th>#</th>
                                <th>分类名称</th>
                                <th>状态</th>
                                <th>操作</th>
                            </tr>
                            @foreach($cates as $cate)
                            <tr>
                                <td>{{ $cate->id }}</td>
                                <td>{{ $cate->cate_name }}</td>
                                <td>
                                    <select name="cate_status" data-id="{{ $cate->id }}" class="status">
                                        <option value="1" {{ $cate->cate_status==1 ? 'selected' : '' }} >显示</option>
                                        <option value="0" {{ $cate->cate_status==0 ? 'selected' : '' }} >隐藏</option>
                                    </select>
                                </td>
                                <td>
                                    <a href="{{ url("/admin/faq/add",[$cate->id]) }}" class="btn btn-success">添加内容</a>
                                    <a href="{{ url("/admin/faq/fc/{$cate->id}/edit") }}" class="btn btn-info">编辑</a>
                                    <a href="{{ url('/admin/faq/fc',['id'=>$cate->id]) }}" class="btn btn-danger cate-del">删除</a>
                                </td>
                            </tr>
                            @endforeach
                        </table>
                    </div>
                    <!-- /.box-body -->
                    <div class="box-footer">
                        {!! $cates->appends(['cate_name'=>old('cate_name')])->render() !!}
                    </div>
                </div>
                <!-- /.box -->
            </div>
        </div>
    </section>
    <!-- /.content -->
</div>
@endsection
@section('pluginscript')
<!-- Slimscroll -->
<script src="{{ asset('/dist/admin/plugins/slimScroll/jquery.slimscroll.min.js') }}"></script>
<!-- FastClick -->
<script src="{{ asset('/dist/admin/plugins/fastclick/fastclick.js') }}"></script>
<script type="text/javascript">
    $(function(){
        $.ajaxSetup({
            headers: {
                'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
            }
        });
        // 显示隐藏
        $('.status').change(function(){
            var url = '{{ url("/admin/faq/fc/isshow") }}';
            var data = {};
            data.id = $(this).attr('data-id');
            data.status = $(this).val();
            
            $.post(url,data, function(msg){
                if(msg.status != '1'){
                    alert(msg.info);
                }
                location.reload();
            });
        });
        // 导航条显示隐藏
        $('.isnav').change(function(){
            var url = '{{ url("/admin/faq/fc/isnav") }}';
            var data = {};
            data.id = $(this).attr('data-id');
            data.isnav = $(this).val();
            
            $.post(url,data, function(msg){
                if(msg.status != '1'){
                    alert(msg.info);
                }
                location.reload();
            });
        });
        
        // 删除
        $('.cate-del').click(function(){
            var url = $(this).attr('href');
            var tr = $(this).parents('tr');
            var result = confirm('确定要删除？');
            
            if(result){
                $.ajax({
                    url: url,
                    type:'DELETE',
                    success:function(msg){
                        if(msg.status == '1'){
                            tr.remove();
                        } else {
                            alert(msg.info);
                        }
                    }
                });
            }
            return false;
        });
        
    })
</script>
@endsection
